package com.jinmdz.fmis.dao.dao.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

import java.util.Date;

/**
 * 火化时间段Provider
 *
 * @author LiCongLu
 * @date 2020-03-08 15:59
 */
public class CremationTimeSegmentProvider {

    /**
     * 按照获取日期，查询火化预约时间预约情况
     *
     * @param furnaceTypeCode 火化炉类型
     * @param appointmentDate 火化预约日期
     * @return
     * @author LiCongLu
     * @date 2020-03-08 15:57
     */
    public String listAppointmentTimeSegmentCountByDate(@Param("furnaceTypeCode") Integer furnaceTypeCode, @Param("appointmentDate") Date appointmentDate) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append("  appointment_time_segment,sort");
                // 统计此预约时间段预约个数
                builder.append("  ,( select COUNT(*) from cremation where cremation.deleted = 0 ");
                builder.append("    and cremation.furnace_type_code = #{furnaceTypeCode} and cremation.appointment_date = #{appointmentDate}");
                builder.append("    and as_appointment = 1 and cremation.appointment_time_segment = cremation_time_segment.appointment_time_segment ");
                builder.append("    ) as appointment_count");
                SELECT(builder.toString());
                FROM(" cremation_time_segment ");
                WHERE(" deleted = 0 ");
                WHERE(" furnace_type_code = #{furnaceTypeCode}");
                ORDER_BY(" sort ");
            }
        }.toString();
    }
}